package me.send.data.service.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import me.send.business.base.Pager;
import me.send.business.base.SendVariable;
import me.send.data.service.mapper.BrokerMapper;
import me.send.data.service.pojo.Broker;
import me.send.framework.util.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BrokerService {

	@Autowired
	private BrokerMapper brokerMapper;

	
	public Map<String, Object> batch_delete(String brokerids){
		Map<String, Object> result = new HashMap<String, Object>();
		result.put(SendVariable.DATA, SendVariable.ERROR);
		// 返回数据 2015年6月18日18:12:08
		if (brokerids!=null && !brokerids.equals("")) {
			Map<String, Object> parameter = new HashMap<String, Object>();
			parameter.put("brokerids", brokerids);
			brokerMapper.batch_delete(parameter);
			result.put(SendVariable.DATA, SendVariable.SUCCESS);
		}
		return result;
	}
	
	public Map<String, Object> broker_login(String username, String password) {
		Map<String, Object> result = new HashMap<String, Object>();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put(SendVariable.DATA, SendVariable.ERROR);
		if (username != null && !"".equals(username) && password != null
				&& !"".equals(password)) {
			Map<String, Object> parameter = new HashMap<String, Object>();
			parameter.put("username", username);
			password = MD5Util.MD5(password);
			parameter.put("password", password);
			result = brokerMapper.broker_login(parameter);
			map.put(SendVariable.DATA, SendVariable.SUCCESS);
			map.put(SendVariable.RESULTMAP, result);
		}
		return map;
	}
	
	// 使用分页查询
	public Map<String, Object> page(Pager pager,Broker broker){
		Map<String, Object> parameter = new HashMap<String, Object>();
		Map<String, Object> result = new HashMap<String, Object>();
		if (pager==null) {
			pager = new Pager(); 
		}
		parameter.put(SendVariable.PAGE, pager);
		parameter.put(SendVariable.DATA, broker);
		List<Map<String, Object>> rows = brokerMapper.page(parameter);
		Integer total = brokerMapper.count(parameter);
		result.put(SendVariable.ROWS, rows);
		result.put(SendVariable.TOTAL, total);
		return result;
	}
}
